<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>登录</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/main.js"></script> 
<style >
#validateCode{
  margin-left:-25px;
}
#input{
margin-left:-30px;
width:78px;
}
</style>
</head>

<body id="login" onclick="keyLogin();">
	<div id="login_header">
    	<div class="login_hc">
        </div>
    </div>
    <div id="login_content" >
    	<span class="login_welcome">欢迎使用本系统</span>
        <div class="login_logo"></div>
        <form name="loginForm"  method="post" action="login!login">
        <div class="login_panel">
        	<ul>
				<li><span>用户名：</span><input class="info" type="text" name="username" value=""  maxLength=11/></li>   
                <li><span>密码：</span><input class="info" type="password" name="pw" value=""  maxLength=6/></li> 
                <li id="validateCode"><span>认证码：</span> <span><input class="info" id="input" type="text" value=""  maxLength=4/></span><span><input style="width:88px" type ="button" id="code" onclick="createCode()"/></span> </li>      
            </ul>
            <div class="login_do">
            	<span class="total_bg do_submit" id="submit" onclick="check()"/>确定</span>
           		<span class="total_bg cancel" onclick="cancel()">取消</span>
            </div>
            <div id="msg"><font color="red">${msg}</font></div>
            <div class="login_tips">
                <p>*如有问题请及时联系管理员</p>
            </div>
        </div>
        </form>
    </div>
    <div id="login_footer">技术支持：天津神舟通用数据技术有限公司</div>
    <script language=javascript>
    
    var code ; //在全局定义验证码   
  //产生验证码  
  window.onload = createCode();
  function createCode(){  
      code = "";   
      var codeLength = 4;//验证码的长度  
      var checkCode = document.getElementById("code");   
      var random = new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R',  
      'S','T','U','V','W','X','Y','Z');//随机数  
      for(var i = 0; i < codeLength; i++) {//循环操作  
         var index = Math.floor(Math.random()*36);//取得随机数的索引（0~35）  
         code += random[index];//根据索引取得随机数加到code上  
     }  
     checkCode.value = code;//把code值赋给验证码  

 }  
  //校验验证码  
  function validate(){
      var inputCode = document.getElementById("input").value.toUpperCase(); //取得输入的验证码并转化为大写        
      if(inputCode.length <= 0) { //若输入的验证码长度为0  
          alert("请输入验证码！"); //则弹出请输入验证码  
          createCode();
      }         
      else if(inputCode != code ) { //若输入的验证码与产生的验证码不一致时  
          alert("验证码输入错误！@_@"); //则弹出验证码输入错误  
          setTimeout(createCode(),400);//刷新验证码  
          document.getElementById("input").value = "";//清空文本框  
      }         
      else { //输入正确时  
    	  document.forms[0].submit();

      }             
  }  
    
	function check() {
		
		var username = document.forms[0].username.value;
		var password = document.forms[0].pw.value;
		if (username.length == 0) {
			alert("请输入用户ID!");
			document.forms[0].username.focus();
			createCode();
		} else if (password.length == 0) {
			alert("请输入用户密码!");
			document.forms[0].password.focus();
			createCode();
		} else {
			validate();
			/* document.forms[0].submit(); */
		}
	}
	function cancel(){
		
		$(".info").val("");
	}
	function keyLogin(){
		
		  if ((event.keyCode) == 13){
			  check();
		  }   
		}
</script>

</body>
</html>
